package api

import (
	"gitee.com/zatto/maudit/apps/audit"
	restfulspec "github.com/emicklei/go-restful-openapi/v2"
	"github.com/emicklei/go-restful/v3"
	"github.com/infraboard/mcube/app"
)

type handler struct {
	service audit.Service
}

func (h *handler) Config() error {
	h.service = app.GetInternalApp(audit.AppName).(audit.Service)
	return nil
}

func (h *handler) Name() string {
	return audit.AppName
}

func (h *handler) Version() string {
	return "v1"
}

func (h *handler) Registry(ws *restful.WebService) {
	tags := []string{"审计日志"}
	ws.Route(ws.GET("/").To(h.QueryAuditLog).
		Doc("查询审计日志列表").
		Reads(*audit.NewQueryAuditLogRequest()).
		Metadata(restfulspec.KeyOpenAPITags, tags).
		Metadata("auth", true).
		Metadata("resource", "审计日志列表").
		Returns(200, "OK", audit.AuditLogSet{}))
}

func init() {
	app.RegistryRESTfulApp(&handler{})
}
